package _01grammar

//逻辑控制语句
def x = 1.2
def result
//可以匹配字符串、数组、范围等,任意类型
//可以有效解决多重if else
switch (x) {
    case 'foo':
        result = 'foot'
        break
    case Integer:
        result = 'int'
        break
    case 12..20:
        result = 'range'
        break
    case [1.2, 'hello']://列表,会被优先匹配到，包含x的值
        result = 'list'
        break
    case BigDecimal: //因为上面的list被优先匹配到break此处不会匹配
        result = 'bigDecimal'
        break
    default:
        result = 'default'
        break
}
println result

//for
def sum = 0
//迭代范围类型
for (i in 0..9) {
    sum += i
}
println sum